package service.impl;

import dao.UserDao;
import org.springframework.stereotype.Service;
import pojo.User;
import service.UserService;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service("userServiceDB")
public class UserServiceDBImpl implements UserService{

    @Resource
    private UserDao userDao;

    @Override
    public User add(User user) {
       user.setId(UUID.randomUUID().toString());
       int m = userDao.add(user);
       if (m>0){
           return user;
       }else{
           return null;
       }
    }

    @Override
    public List<User> getAllUser() {
        return userDao.findAll();
    }

    @Override
    public User delete(String id) {
        int m = userDao.delete(id);
        if (m>0){
            User user = new User();
            user.setId(id);
            return  user;
        }else{
            return null;
        }
    }

    @Override
    public User update(User user) {
        int m = userDao.update(user);
        if (m>0){
            return user;
        }else{
            return null;
        }
    }
}
